//
//  SZYingKUMainViewController.m
//  KaiJing
//
//  Created by lanou on 16/1/11.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "SZYingKUMainViewController.h"
#import <MJExtension.h>

#import "HYMovieMainView.h"
#import "PKRequestManager.h"
#import "HYMovieDateModel.h"
#import "HYMainMoviePlagerViewController.h"
#import "HYMovieDateTableViewController.h"
#import "CJPictorialCellWebViewViewController.h"
#import "HYMovieMoreViewController.h"
@interface SZYingKUMainViewController ()<UIScrollViewDelegate,bigImageButton>

@property (nonatomic, strong) HYMovieMainView *bigView;
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation SZYingKUMainViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.translucent = NO;
    [self setUpData];
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"更多" style:(UIBarButtonItemStylePlain) target:self action:@selector(rightButtonAction:)];
    self.navigationItem.rightBarButtonItem = rightButton;
}



- (void)jsonModel
{
    NSDictionary *dict = @{
                           @"subject" : self.title,
                           @"message" :_bigView.message.text
                    
};
    HYYingKuMainModel *model = [HYYingKuMainModel mj_objectWithKeyValues:dict];
}


#pragma mark -- 解析数据--
- (void)setUpData
{
    NSUUID *uuid = [UIDevice currentDevice].identifierForVendor;
    NSString *uuidString = uuid.UUIDString;
    NSString *string = [NSString stringWithFormat:@"http://morguo.com/forum.php?mod=allthreadtovisit&orderbynew=1&androidflag=1&appfrom=ios&iosversion=3.13&page=1&deviceid=%@",uuidString];
//    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    
    [PKRequestManager requestWithUrlString:string parDic:nil method:GET finish:^(NSDictionary *dataDic) {
        
       NSArray *listArray = dataDic[@"data"][@"list"];
        _dataArray = [NSMutableArray array];
        
        for (NSDictionary *dic in listArray) {
            _model = [[HYYingKuMainModel alloc] init];
            [_model setValuesForKeysWithDictionary:dic];
            
            [_dataArray addObject:_model];
            
            
        }
        
       
    [self addView]; 
      
    } error:^(NSError *error) {
        
    }];

}

#pragma mark --初始化uivew
- (void)addView {
    
    _bigView = [[HYMovieMainView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    _bigView.array = [NSMutableArray array];
    _bigView.array = _dataArray;
    self.view = _bigView;
    
    _bigView.scrollView.delegate = self;
    
    _bigView.delegate = self;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [_bigView addGestureRecognizer:tap];
    
    HYYingKuMainModel *model = _dataArray[0];
    self.navigationItem.title = model.subject;
   }


#pragma mark --跳转更多界面
- (void)rightButtonAction:(UIBarItem *)button {
    HYMovieMoreViewController *moreVc = [[HYMovieMoreViewController alloc] init];
    [self.navigationController pushViewController:moreVc animated:YES];
}

/** 点击大的image的图片触发方法*/
- (void)changeBigImageButton:(UIButton *)button
{
   
    [button addTarget:self action:@selector(buttonClick:) forControlEvents:(UIControlEventTouchUpInside)];
}

- (void)buttonClick:(UIButton *)button {
    
    HYMainMoviePlagerViewController *mainMoviePlayerVc = [[HYMainMoviePlagerViewController alloc] init];
    mainMoviePlayerVc.playerArray = _dataArray;
    mainMoviePlayerVc.playerModel = _model;
    mainMoviePlayerVc.tabBarController.tabBar.hidden = YES;
    [self.navigationController pushViewController:mainMoviePlayerVc animated:NO];
    
    
}

#pragma mark --滑动触发方法--
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    float content = scrollView.contentOffset.y / kScreenHeight;
    
        for (int i  =1 ; i <= content; i ++) {
        _model = _dataArray[i];
        self.navigationItem.title = _model.subject;
        
    }
    if (content <1) {
        _model = _dataArray[0];
        self.navigationItem.title = _model.subject;
    }
   
}

#pragma mark --轻拍手势触发方法--
-(void)tapAction:(UITapGestureRecognizer *)tap {
    
    CJPictorialCellWebViewViewController *YKWebView = [[CJPictorialCellWebViewViewController alloc] init];
    YKWebView.tid = _model.tid;
    [self.navigationController pushViewController:YKWebView animated:YES];
    
//    HYMovieDateTableViewController *movieDetaVc = [[HYMovieDateTableViewController alloc] init];
//    movieDetaVc.model = _model;
//    [self.navigationController pushViewController:movieDetaVc animated:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
